<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<link rel="stylesheet" type="text/css" media="screen" href="css/smoothness/jquery-ui-1.9.0.custom.css" />	<!-- jqueryUI CSS -->
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />							<!-- jqGrid CSS -->
<link rel="stylesheet" type="text/css" media="screen" href="css/selfTemplate.css" />						<!-- 本專案自行定義 CSS -->

<script src="js/jquery-1.8.0.min.js" type="text/javascript"></script>										<!-- jQuery 核心 -->
<script src="js/grid.locale-tw.js" type="text/javascript"></script>											<!-- jqGrid 語系檔 -->
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>										<!-- jqGrid 核心 -->
<script src="js/jquery-ui-1.9.0.custom.min.js" type="text/javascript"></script>							<!-- jqueryUI 核心 -->
<script src="js/widgets.js" type="text/javascript"></script>												<!-- 本專案自行定義 JS -->
<script src="js/jquery.checkboxtree.min.js" type="text/javascript"></script>								<!-- CheckBox樹的 JS -->

<title>帳務研究所-交付申請 </title>

<script type="text/javascript">

function checkDuplicated(grid) {
	var squadId = $("#squadid")[0].value;
	var ll = $("#detailTable_"+grid).jqGrid('getDataIDs');
	var isDuplicated = false;
	for(var i=0;i<ll.length;i++){
		if (ll[i] == squadId ) {
			isDuplicated = true;
		}
	}
	
	if (isDuplicated) {
		alert(squadId+"已經存在，部署小組ID不可重覆 !");
	} else {
		var squadName = $("#squadname")[0].value;
		var dataAdd = {"squadid":squadId,"squadname":squadName,"creator":"842297","createdDateTime":"FFFFFF"};
		var _iCount = $("#detailTable_"+grid).jqGrid('getGridParam', 'records');
		$("#detailTable_"+grid).jqGrid('addRowData', _iCount+1,dataAdd);
	} 
	return [];
}

function buildGrid(grid){
	$("#masterTable_"+grid).jqGrid({
		url:'QueryEnv',
		postData: {
			subSysId: function() { return grid; },
		},
		datatype: "json",
	   	colNames:['環境ID', '環境名稱','創建人員', '創建日期'],
	   	colModel:[
	   		{name:'envid',index:'envid',editable:true, edittype:"text",editrules:{required:true},editoptions: {size:20, maxlength: 20}},
	   		{name:'envname',index:'envname',editable:true, edittype:"text",
	   			editrules:{custom:true,required:true,custom_func:function(){
	   				$("#isNotDuplicated")[0].value = true;
	   				var envId = $("#envid")[0].value;
	   				var envName = $("#envname")[0].value;
	   				var tabIdx = $("#tabsDiv").tabs("option", "selected");
	   				
   					$("#bssId_form")[0].value = "MBMS";
   					$("#subSysId_form")[0].value = $("#tab_"+tabIdx).attr("subSys");
   					$("#envId_form")[0].value = envId;
   					$.post("IsDuplicated",$("#q_form").serializeArray(),function(res) {
   						if (res == "true") {
   							$("#isNotDuplicated")[0].value = false;	
   						}
   					},"TEXT");
   					var rr = $("#isNotDuplicated")[0].value;
					return [rr,"環境ID重複了，換一個!"];
	   			}	// custom_func 結尾
	   		}	//  editrules 結尾
	   		},
	   		{name:'creator',index:'creator'},
	   		{name:'createdDateTime',index:'createdDateTime'}
	   	],
	   	rowNum:10,
	   	pager: "#masterPager_"+grid,
		multiselect: false,
		rownumbers: true,
	   	viewrecords: true,	
		caption: "環境",
		onSelectRow: function(ids) {
			jQuery("#detailTable_"+grid).jqGrid("setCaption","部署小組所屬的環境--"+ids);
			jQuery("#detailTable_"+grid).jqGrid('setGridParam',{
				url:"QuerySquad",
				postData: {
					tarSys: function() { return "MBMS"; },
					tarSubSys: function() {
						return grid; 
					},
					tarEnv: function() { return ids; },
				}
			//});
			}).trigger('reloadGrid');
		},
		/**	This event is executed immediately after every server request. **/
		loadComplete: function(data) {
			jQuery("#detailTable_"+grid).jqGrid({
				datatype: "json",
				postData: {
					getDataType: function() { return "mapping"; },
				},
				colNames:["<input type='checkbox' onclick='checkBox(event)' />",'部署小組ID', '部署小組名稱','部署路徑','創建人員', '創建日期'],
			   	colModel:[
					{name:'my_checkbox',index:'my_checkbox', edittype:"checkbox",
					formatter: "checkbox", formatoptions: {disabled:false},width:40,align:"center" },
			   		{name:'squadid',index:'squadid',editable:true,editrules:{required:true}},
			   		{name:'squadname',index:'squadname',editable:true,editrules:{required:true}},
			   		{name:'path',index:'path',editable:true,editrules:{required:true}},
			   		{name:'creator',index:'creator'},
			   		{name:'createdDateTime',index:'createdDateTime'}
			   	],
			   	rowNum:10,
			   	loadonce:false,
			   	rowList:[10,20,30],
			   	pager: "#detailPager_"+grid,
				multiselect: false,
				rownumbers: true,
			   	viewrecords: true,
			   	editurl: "ManipulateGridSquad",
				caption:"部署小組所屬的環境"
			}).navGrid("#detailPager_"+grid,{add:false,edit:false,del:false}
			,{}
			,{}
			,{});		
		}
	}).jqGrid("navGrid","#masterPager_"+grid,{add:false,edit:false,del:false},
			{},{},{});
}

function ock(item) {
	$("#li_"+item).append("&nbsp;&nbsp;<input type='text'/>");
}

$(document).ready(function() {
	
	$("#getDataType")[0].value = "JSON";
	$.post("QuerySubSys",$("#q_form").serializeArray(),function(res) {
		$.each(res,function(i, tmp) {
			$("#tabsUlSquad").append("<li><a id=\"tab_"+i+"\" no=\""+i+"\" subSys=\""+tmp.id+"\" href=\"#tab_"+tmp.id+"\">"+tmp.name+" ("+tmp.id+")</a></li>");
			$("#tabsDivSquad").append("<div id=\"tab_"+tmp.id+"\"><table id=\"masterTable_"+tmp.id+"\"></table><div id=\"masterPager_"+tmp.id+"\"></div><p><table id=\"detailTable_"+tmp.id+"\"></table><div id=\"detailPager_"+tmp.id+"\"></div>");
			buildGrid(tmp.id);
		});
		
		$("#tabs").tabs();
		$("#tabs-4").tabs();
	},"JSON");
	$("#getDataType")[0].value = "";
	
	$.post("QuerySVN",function(svnRep) {
		$.each(svnRep,function(i, res) {
			var home = res.home;
			home = home.replace( new RegExp ( "/" , "gm" ), "\\/");
			var id = res.id;
			id = id.replace( new RegExp ( "/" , "gm" ), "\\/");
			if (res.isDir) {		//目錄
				$("#"+home).append("<li><input type='checkbox' id='chk_"+id+"'><label>"+res.id+"</label><ul id='"+res.id+"'></ul>");
			} else {
				$("#"+home).append("<li id='li_"+id+"'><input type='checkbox' id='chk_"+id+"'><select id='sel_"+id+"'></select>&nbsp;<label>"+res.id+"</label>");
				//$("#"+home).append("<li id='li_"+id+"'><input type='checkbox' id='chk_"+id+"' onclick='ock('"+id+"');'  ><select id='sel_"+id+"'></select>&nbsp;<label>"+res.id+"</label>");
				var ver = res.ver;
				for(i=ver;i>=1;i--) {
					$("#sel_"+id).append("<option>"+i+"</option>");
				}
			}
		});
	},"JSON");
	 
	 $("#grid1").jqGrid({
			url:'QueryReq',
			datatype: "json",
		   	colNames:["<input type='checkbox' onclick='checkBox(event)' />","需求編號", "需求名稱","創建系統"],
		   	postData: {
				getDataType: function() { return "mapping"; },
			},
		   	colModel:[
				{name:"my_checkbox",index:"my_checkbox", edittype:"checkbox",
				formatter: "checkbox", formatoptions: {disabled:false},width:40,align:"center" },
		   		{name:"reqid",index:"reqid"},
		   		{name:"reqName",index:"reqName"},
		   		{name:"sysFrom",index:"sysFrom"}
		   	],
		   	width:460,
		   	rowNum:20,
		   	pager: "#pager1",
			multiselect: false,
			rownumbers: true,
		   	viewrecords: true,	
			caption: "選擇需求"
		});
		jQuery("#grid1").jqGrid("navGrid","#pager1",{add:false,edit:false,del:false});
		
		$('#root').checkboxTree();
		
		
		$("button").button();
});
</script>

</head>
<body>
<div id="funcDisplay">
帳務研究所-交付申請
</div>
<form id="q_form">
	<input type="hidden" id="getDataType" name="getDataType" />
	<input type="hidden" id="bssId_form" name="bssId_form" />
	<input type="hidden" id="subSysId_form" name="subSysId_form" />
	<input type="hidden" id="envId_form" name="envId_form" />
</form>
<input id="subsyses" type="hidden" >
<input id="isNotDuplicated" type="hidden" >

<br/>
<button type="button">提交</button>
<p>

<div id="tabs">
    <ul>
        <li><a href="#tabs-1">選擇需求</a></li>
        <li><a href="#tabs-4">選擇欲部署的Squad</a></li>
        <li><a href="#tabs-2">選擇程式</a></li>
        <li><a href="#tabs-3">選擇通知人員</a></li>
    </ul>
    <div id="tabs-1">
	    <table id="grid1"></table>
		<div id="pager1"></div>
    </div>
    <div id="tabs-4">
        <ul id="tabsUlSquad"></ul>
		<div id="tabsDivSquad"></div>
    </div>
    <div id="tabs-2">
		<ul id="root"></ul>
	</div>
	
		<div id="tabs-3">
			<table>
				<tbody id="tBodyTPOwner">
					<tr bgcolor="#CCCCCC">
						<td><input type="checkbox" checked="checked"
							nickname="陳安民" value="026312"></td>
						<td>1</td>
						<td>陳安民 (026312)</td>
					</tr>
					<tr bgcolor="#FFFFFF">
						<td><input type="checkbox" checked="checked"
							nickname="邊曉虹" value="029108"></td>
						<td>2</td>
						<td>邊曉虹 (029108)</td>
					</tr>
					<tr bgcolor="#CCCCCC">
						<td><input type="checkbox" checked="checked"
							nickname="魏慶麟" value="030906"></td>
						<td>3</td>
						<td>魏慶麟 (030906)</td>
					</tr>
					<tr bgcolor="#FFFFFF">
						<td><input type="checkbox" nickname="廖明得"
							value="031918"></td>
						<td>4</td>
						<td>廖明得 (031918)</td>
					</tr>
					<tr bgcolor="#CCCCCC">
						<td><input type="checkbox" nickname="詹金蘭"
							value="034058"></td>
						<td>5</td>
						<td>詹金蘭 (034058)</td>
					</tr>
					<tr bgcolor="#FFFFFF">
						<td><input type="checkbox" nickname="朱彥聰"
							value="034210"></td>
						<td>6</td>
						<td>朱彥聰 (034210)</td>
					</tr>
					<tr bgcolor="#CCCCCC">
						<td><input type="checkbox" nickname="吳勛誠"
							value="035853"></td>
						<td>7</td>
						<td>吳勛誠 (035853)</td>
					</tr>
					<tr bgcolor="#FFFFFF">
						<td><input type="checkbox" nickname="林志維"
							value="036119"></td>
						<td>8</td>
						<td>林志維 (036119)</td>
					</tr>
					<tr bgcolor="#CCCCCC">
						<td><input type="checkbox" nickname="黃智賢"
							value="036692"></td>
						<td>9</td>
						<td>黃智賢 (036692)</td>
					</tr>
					<tr bgcolor="#FFFFFF">
						<td><input type="checkbox" nickname="張秀娟"
							value="037419"></td>
						<td>10</td>
						<td>張秀娟 (037419)</td>
					</tr>
					<tr bgcolor="#CCCCCC">
						<td><input type="checkbox" nickname="李俊賢"
							value="041265"></td>
						<td>11</td>
						<td>李俊賢 (041265)</td>
					</tr>
				</tbody>
			</table>
		</div>
	</div>
</body>
</html>